package org.springblade.modules.auth.endpoint;

import lombok.AllArgsConstructor;
import org.springblade.common.constant.CommonConstant;
import org.springblade.core.launch.constant.AppConstant;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.tool.api.R;
import org.springblade.modules.auth.bean.RsLicense;
import org.springblade.modules.auth.utils.RsLicenseUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@RequestMapping(AppConstant.APPLICATION_AUTH_NAME)
public class RsLicenseEndpoint {

	@Value("${rslen}")
	private String licenseFile;

	@GetMapping("/license")
	public R<RsLicense> getLicense()  {
		try{
			RsLicense rsLicense = RsLicenseUtils.readLicenseFile(licenseFile);
			return R.data(rsLicense);
		}catch (Exception e){
			throw new ServiceException("请联系管理员,后台故障");
		}
	}

}
